package com.wngbms.feigndemo.controller;

import com.alibaba.fastjson.JSON;
import com.wngbms.feigndemo.annotation.ToBeTracedRequest;
import com.wngbms.feigndemo.service.TraceServ;
import com.wngbms.feigndemo.vo.BaseReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class TraceController {

    @Autowired
    TraceServ traceServ;

    @ToBeTracedRequest(fieldName = "seqId", entityIndex = 0)
    @PostMapping("/echo0")
    public String echo0(@RequestBody BaseReq baseReq) {
        log.info("echo0... {}", JSON.toJSONString(baseReq));
        traceServ.doSomething();
        return "hello";
    }

    @PostMapping("/echo1")
    public String echo1(@RequestBody BaseReq baseReq) {
        log.info("echo0... {}", JSON.toJSONString(baseReq));
        traceServ.doSomething();
        return "hello";
    }

}
